#include <string.h> /* strcpy() */
#include <stdio.h>  /* fgets() */
#include <stdlib.h>
#include "nml.hh"   /* nmlSetHostAlias */
#include "zucglb.h" /* these decls */
#include "zuccfg.h" /* their initial values */
#include "rcs_print.hh"
#include "log/zuclog.h"

int zucGetArgs(int argc, char* argv[])
{
    int t;

    /* process command line args, indexing argv[] from [1] */
    for (t = 1; t < argc; t++)
    {
        if (!strcmp(argv[t], "-v"))
        {
            zucEnableStdout(1);
            zuclog_info("MAIN", "log set DEBUG level");
            zucSetLogLevel(ZLOGLV_D);
            continue;
        }
        if (!strcmp(argv[t], "-vv"))
        {
            zucEnableStdout(1);
            zuclog_info("MAIN", "log set TRACE level");
            zucSetLogLevel(ZLOGLV_T);
            continue;
        }

        if (!strcmp(argv[t], "-c"))
        {
            zuc_cab_type = atoi(argv[t + 1]);

            zuclog_info("MAIN", "arguments zuc_cab_type = %d\n", zuc_cab_type);
            if (zuc_cab_type == 0)
                zuc_cab_type = 2;  // take it as cab 2.1 when in bootloader
            t++;
            continue;
        }

        // printf("zuctaskmod: simulation option = %s\n", argv[t]);
        if (!strcmp(argv[t], "-S"))
        {  // simulation without both CANs
            zuc_sim = ZUC_SIM_ENA_SOFT;
            continue;
        }
        else if (!strcmp(argv[t], "-E"))
        {  // simulation on real device, need SCB CAN, not servo CAN
            zuc_sim = ZUC_SIM_ENA_ON_DEV;
            continue;
        }
        else if (!strcmp(argv[t], "-D"))
        {  // real device, need both CANs
            zuc_sim = ZUC_SIM_DISABLED;
            continue;
        }
    }
    /* else not recognized-- ignore */

    return 0;
}
